<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/12/29
  Time: 8:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日志管理</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link type="text/css" href="../layui/css/layui.css" rel="stylesheet">
    <script type="text/javascript" src="../layui/layui.js"></script>
    <style type="text/css">
        /*.layui-table-cell{
            height:auto!important;
            white-space:normal;
        }*/
        .layui-table-cell{
            text-align:center;
            height: auto!important;
            white-space: normal;
        }
        .layui-table img{
            max-width: 120PX
        }
        .layui-form-label{
            width: 100px;
        }


    </style>
    <script type="text/javascript">
        layui.use(['layer', 'form',"table","jquery","upload"], function(){
            var layer = layui.layer
            var form = layui.form;
            var table=layui.table
            var $=layui.jquery
            var upload = layui.upload;
            table.render({
                elem:"#log"
                ,url:"${pageContext.request.contextPath}/selectLogByPage"
                ,toolbar:"#toolbarDemo"
                ,page:true
                ,cols:[[
                    {type:"checkbox"}
                    ,{field:"logId",title:"编号",align:"center"}
                    ,{field:"adminId",title:"用户id",align:"center"}
                    ,{field:"logDate",title:"日志时间",align:"center"}
                    ,{field:"logContent",title:"日志内容",align:"center"}
                    ,{field:"logType",title:"日志类别",align:"center"}
                    ,{field:"logIp",title:"ip",align:"center"}
                    ,{title:"操作",templet:"#caoZuoTemplet",align:"center"}
                ]]
                ,done: function(res, curr, count){
                    //如果是异步请求数据方式，res即为你接口返回的信息。
                    //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                    console.log(res.typeList);
                    $("#lei").html("")
                    $("#lei").append("<option value=''>请选择日志类型</option>")
                    for (var i=0;i<res.typeList.length;i++){
                        $("#lei").append("<option value='"+res.typeList[i]+"'>"+res.typeList[i]+"</option>")
                    }
                    form.render(); //更新全部
                }
            })
            table.on('toolbar(logFilter)', function(obj){
               // var checkStatus = table.checkStatus(obj.config.id);
                var content=$("#nameInput").val()
                var type=$("#lei").val();
                if(obj.event=="switch"){
                    table.reload('log', {
                        where: {"content":content,"type":type} //设定异步数据接口的额外参数
                    });
                }else if (obj.event=="delete") {
                    var checkStatus = table.checkStatus('log'); //idTest 即为基础参数 id 对应的值
                    /*console.log(checkStatus.data) //获取选中行的数据*/
                    //获取ids
                    var ids=new Array()
                    for (var i=0;i<checkStatus.data.length;i++) {
                        ids[i]=checkStatus.data[i].logId
                    }
                    if (ids.length == 0) {
                        layer.msg("请选择要删除的行")
                    }else{
                        layer.confirm('确定要删除吗?', function(index){
                            $.ajax({
                                url:"${pageContext.request.contextPath}/deleteLogMany"
                                ,data:{"ids":ids}
                                ,success:function (data) {
                                    var msg="删除失败"
                                    if (data.isOk) {
                                        msg="删除成功"
                                        //重载table
                                        table.reload('log');
                                    }
                                    layer.msg(msg)
                                }
                            })
                            layer.close(index);
                        });
                    }

                }

                /*监听添加工具栏======end*/
            });


            /*//监听行工具栏=========end*/
        });

    </script>

    <!--/*自定义头工具栏模板*/-->
    <script type="text/html" id="toolbarDemo">
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm" lay-event="delete">批量删除</button>
        </div>
        <div class="layui-input-inline">
            <label class="layui-form-label">日志类别</label>
            <div class="layui-input-block">
                <select name="interest" lay-filter="leiFilter" id="lei">
                    <option value="0">写作</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">日志内容</label>
            <div class="layui-input-inline" style="width: 200px;">
                <input type="text" placeholder="请输入日志内容" class="layui-input" id="nameInput">
            </div>
            <button class="layui-btn layui-btn-sm" lay-event="switch">查询</button>
        </div>
        <div class="layui-inline">
            <a class="layui-btn layui-btn-sm" lay-event="daochu" href="${pageContext.request.contextPath}/daochuAllLog">导出Excel</a>
        </div>
    </script>
</head>
<body>
<table id="log" lay-filter="logFilter"></table>


</body>
</html>